#ifndef __INCosa_msgQh
#define __INCosa_msgQh

#include "osa_common.h"

#include <pthread.h>
#include <semaphore.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct  stMsgItem
{
	char* psz_buf;
}MSG_ITEM;

typedef struct stMsgQueue
{
	int n_maxMsgs;
	int n_maxMsgLength;
	int n_options;

	int n_head;
	int n_tail;
	int n_numMsgs;

	sem_t sem_mutex;
	sem_t sem_full;
	sem_t sem_empty;

	MSG_ITEM* pst_msgBufs;
}MSG_QUEUE;

typedef MSG_QUEUE* MSG_Q_ID;

/* MSGQ Create Option */
#define MSG_Q_FIFO			0x00
#define MSG_Q_PRIORITY		0x01

/* msg send priority */
#define MSG_PRI_NORMAL 0
#define MSG_PRI_URGENT 1
	
	ESE_API MSG_Q_ID msgQCreate(int maxMsgs, int maxMsgLength, int options);
	ESE_API STATUS 	msgQDelete(MSG_Q_ID msgQId);
	ESE_API STATUS 	msgQSend(MSG_Q_ID msgQId, char *buffer, UINT nBytes,
		int timeout, int priority);
	ESE_API int 	msgQReceive(MSG_Q_ID msgQId, char *buffer, UINT maxNBytes,
		int timeout);
	ESE_API int 	msgQNumMsgs(MSG_Q_ID msgQId);

#ifdef __cplusplus
}
#endif

#endif
